home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 9
/
QRZ Ham Radio Callsign Database - Volume 9.iso
/
mac
/
unix
/
src
/
mknlist.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-24
|
1KB
|
79 lines
#include <stdio.h>
#include <string.h>
#include "cb.h"
main(argc,argv)
int argc;
char *argv[];
{
FILE *fp;
FILE *op;
long pos;
char str[1024];
char buf[40];
char *f[20];
char *p;
struct nind indx;
int recs;
int n, maxn;
if (!argv[1])
{
printf("Usage: %s dbase_name\n",argv[0]);
exit(1);
}
if ((fp=fopen(argv[1],"r")) == NULL)
{
printf("Error opening file %s.\n",argv[1]);
exit(1);
}
if ((op=fopen("nlist.ndx","w")) == NULL)
{
printf("Error opening nlist.ndx\n");
exit(1);
}
recs = 0;
maxn = 0;
printf("\n");
while (!feof(fp))
{
memset(str,0,sizeof(str));
memset(&indx,0,sizeof(struct nind));
indx.pos = ftell(fp);
fgets(str,sizeof(str),fp);
if (!strlen(str))
break;
if (strlen(str) < 20) /* skip the cross references */
continue;
field_it(str,f);
sprintf(buf,"%s %s %s",f[LNAME],f[FNAME],f[MI]);
n = strlen(buf);
if (n > sizeof(indx.name)-1)
{
/*
printf("%s\n",buf);
*/
maxn++;
}
buf[sizeof(indx.name)-1] = '\0';
strcpy(indx.name,buf);
fwrite(&indx,sizeof(indx),1,op);
recs++;
if (recs%10000 == 0)
printf("\n%d records written\n\n",recs);
}
fclose(fp);
fclose(op);
printf("\nindex created - %d records written, %d trunciated\n",
recs,maxn);
exit(0);
}